//
//  CarsGroup.m
//  12新汽车品牌
//
//  Created by apple on 15/7/31.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "CarsGroup.h"
#import "Car.h"
@implementation CarsGroup

- (instancetype) initWithDic:(NSDictionary *) dic
{
    
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

+ (instancetype) carsWithDic:(NSDictionary *) dic
{
    return [[self alloc] initWithDic:dic];
}

+ (NSArray *) carsToList
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cars_total" ofType:@"plist"];
    
    NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
    
    NSMutableArray *marray = [NSMutableArray array];
    
    for (NSDictionary *dic in dicArray) {
        CarsGroup *group = [CarsGroup carsWithDic:dic];
        
        NSArray *sunarray = group.cars;
        
        NSMutableArray *cararray = [NSMutableArray array];
        for (NSDictionary *sundic in sunarray) {
            Car *car = [Car carWithDic:sundic];
            
            [cararray addObject:car];
        }
        
        group.cars = cararray;
        [marray addObject:group];
        
    }
    return marray;
}

@end
